<template>
    <a-directory-tree v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys" multiple 
        :tree-data="typeData" :field-names="fieldNames" ref="treeRef" @select="handleNodeClick">
        <template #title="{ name, key }">
            {{ name }}
        </template>
    </a-directory-tree>

    <!-- <div class="head-container">
        <el-tree :tree-data="fileStore.types" :props="{ label: 'name', children: 'children' }" 
            :filter-node-method="filterNode" ref="treeRef" 
            @node-click="handleNodeClick">
            <template #default="{ node, data }">
                <view style="padding-right: 15px;">
                </view>
                {{ node.label }}

            </template>
        </el-tree>
    </div> -->
</template>
<script setup>
import useApp from '@/hooks'
const { $ } = useApp()
import useFileStore from '../../store/file';
const fileStore = useFileStore()
const fieldNames = {
    children: 'child',
    title: 'name',
};
const typeData = ref([])
const name = ref('')
const expandedKeys = ref([]);
const selectedKeys = ref([]);
const emit = defineEmits(['confirm'])
const props = defineProps({
    value: {
        type: [Number, String]
    }
})
// const key = ref()
// const form = ref({
//     jobGradeTypeName: undefined,
//     jobGradeTypeCode: undefined,
//     jobGradeTypeSort: 0,
//     remark: undefined
// })
const treeRef = ref(null)
// const antdModalRef = ref(null)

/** 节点单击事件 */
/* function handleNodeClick(typeData) {
    console.log('typeData---',typeData)
    console.log('typeData.id---',typeData.id)
    // emit('update:value', e.id)
    // emit('confirm', typeData.id)
} */
const handleNodeClick = (selectedKeys, info) => {
      console.log('selected', selectedKeys, info);
      console.log('fileType.id--',info.node.id);
      // emit('update:value', info.node.id)
      emit('confirm', info.node.id)
    };

/** 通过条件过滤节点  */
const filterNode = (value, typeData) => {
    if (!value) return true;
    //return data.label.indexOf(value) !== -1;
    return typeData.name.indexOf(value) !== -1;
};
/** 根据名称筛选部门树 */
watch(name, (val) => {
    proxy.$refs["treeRef"].filter(val);
});
//查询
fileStore.getTypes().then(res => {
    typeData.value = res
})

</script>
  